#ifndef XMLSOCKETENC_HH_
#define XMLSOCKETENC_HH_
#include "Network.hh"
#include <QtCore>
#include <QtNetwork>
#include <QtXml>

/// \brief XML üzenetek küldésére alkalmas socket, ssl titkosítással.
class Network::XmlSocket : public QSslSocket {
    Q_OBJECT

    protected: static QMutex staticLock;

    public: static QSslConfiguration ssl_config(
      QString const& keyPath,
      QString const& certPath,
      QString const& caPath
    );

    /// \brief Mutex a messageBuffer zárolásához.
    protected: QMutex lock;

    protected: u8 size;
    protected: QByteArray inputBuffer;

    /// \brief Üzenetsor.
    protected: QQueue< QDomDocument > messageBuffer;

    public:
    XmlSocket(
      QObject* parent = 0,
      QSslConfiguration const& sslConfig = QSslConfiguration()
    );

    public: QDomDocument read();

    public: void write(QDomDocument& message);

    public: bool messages_available();

    protected: void read_message();

    signals: void message_recieved();

    protected slots: void connection_established();

    protected slots: void read_data();

    protected slots: void errorOccured(const QList<QSslError> &error);

};

#endif // ndef XMLSOCKETENC_HH_
